﻿/*
 * Created by SharpDevelop.
 * User: Corrado Mio
 * Date: 21/06/2012
 * Time: 16:50
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace CSharpExt
{
    /// <summary>
    /// Keep multiple exceptions
    /// </summary>
    public class MultipleException : Exception
    {
        #region Private Data
        
        private List<Exception> _innerExceptions = new List<Exception>();
        
        #endregion
        
        #region Constructor
        
        public MultipleException()
        {
        }
        
        public MultipleException(String message) : base(message)
		{
			
		}
        
        public MultipleException(String message, Exception innerException) : base (message)
		{
            AddException(innerException);
		}
        
        #endregion
        
        #region Properties
        
        public bool ContainsExceptione
        {
            get { return _innerExceptions.Count > 0; }
        }
        
        #endregion
        
        #region Operations
        
        public void AddException(Exception innerException)
        {
            _innerExceptions.Add(innerException);
        }
        
        public override string ToString()
		{
            StringBuilder sb = new StringBuilder(this.ToString());
            
            foreach(Exception ie in _innerExceptions)
            {
                sb.Append("\n----\n").Append(ie.ToString());
            }
            
            return sb.ToString();
		}
        
        #endregion
    }
}
